package demo.jaxrs.server;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.server.mvc.Template;

@Path("/nihao")
public class CustomerService {
	@GET
	public String upload() {
		return "hello";
	}
	@GET
	@Path("/obj")
	@Template(name="/get.ftl")
	public Person getObj() {
		Person person=new Person();
		person.setName("wang wu");
		return person;
	}
	@POST
	@Path("/post")
	@Consumes({MediaType.APPLICATION_FORM_URLENCODED,MediaType.APPLICATION_JSON})
	@Template(name="/post.ftl")
	public Map<String,Object> uploadObj(Person person) {
		System.out.println(person);                
		if(person.getName()==null){
			person.setName("no data!");
		}
                                          Map<String,Object> variable=new HashMap<String, Object>();
		variable.put("person", person);
		return variable;
	}
	@POST
	@Path("/json")
	@Consumes(MediaType.APPLICATION_JSON)
                     @Produces(MediaType.APPLICATION_JSON)
	public Map<String,Object> uploadJson(Person person) {
		Map<String,Object> variable=new HashMap<String, Object>();
		variable.put("person", person);
		//TODO
		return variable;
	}
                     
}

